﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.TMS.VehicleBusinessMappingOverwrite;
using BCDto.TMS.VehicleBusinessMapping;

namespace BCTMSRESTful.Controllers.Management.TMS.VehicleBusinessMappingOverwrite
{
    /// <summary>
    /// 车辆与业务配置重写
    /// </summary>
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class VehicleBusinessMappingOverwriteController : ManagementBaseController
    {
        private readonly IVehicleBusinessMappingOverwriteService vehicleBusinessMappingOverwriteService;

        public VehicleBusinessMappingOverwriteController(IVehicleBusinessMappingOverwriteService vehicleBusinessMappingOverwriteService)
        {
            this.vehicleBusinessMappingOverwriteService = vehicleBusinessMappingOverwriteService;
        }

        #region 添加车辆与业务配置重写
        /// <summary>
        ///  添加车辆与业务配置重写
        /// </summary>
        /// <param name="requestDto">车辆与业务配置重写信息</param>
        /// <response code="201">添加车辆与业务配置重写成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加车辆与业务配置重写")]
        [ProducesResponseType(typeof(VehicleBusinessMappingDto), 201)]
        public IActionResult Post(
            [FromBody] VehicleBusinessMappingOverwriteDto requestDto)
        {
            var result = this.vehicleBusinessMappingOverwriteService.Add(this.Admin,requestDto);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改车辆与业务配置重写
        /// <summary>
        ///  修改车辆与业务配置重写
        /// </summary>
        /// <param name="vehicleBusinessMappingOverwriteId">车辆与业务配置重写Id</param>
        /// <param name="requestDto">车辆与业务配置重写信息</param>
        /// <response code="200">修改车辆与业务配置重写成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{vehicle_business_mapping_overwrite_id}")]
        [Log("修改车辆与业务配置重写")]
        [ProducesResponseType(typeof(VehicleBusinessMappingOverwriteDto), 200)]
        public IActionResult Put([FromRoute(Name = "vehicle_business_mapping_overwrite_id")] int vehicleBusinessMappingOverwriteId, [FromBody] VehicleBusinessMappingOverwriteDto requestDto)
        {
            requestDto.VehicleBusinessMappingOverwriteId = vehicleBusinessMappingOverwriteId;
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingOverwriteService.Update(this.Admin, requestDto));
        }
        #endregion

        #region 删除车辆与业务配置重写
        /// <summary>
        ///  删除车辆与业务配置重写
        /// </summary>
        /// <param name="vehicleBusinessMappingOverwriteId">车辆与业务配置重写Id</param>
        /// <response code="204">删除车辆与业务配置重写成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{vehicle_business_mapping_overwrite_id}")]
        [Log("删除车辆与业务配置重写")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "vehicle_business_mapping_overwrite_id")] int vehicleBusinessMappingOverwriteId)
        {
            this.vehicleBusinessMappingOverwriteService.Delete(this.Admin, vehicleBusinessMappingOverwriteId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取车辆与业务配置重写
        /// <summary>
        ///  获取车辆与业务配置重写
        /// </summary>
        /// <param name="vehicleBusinessMappingOverwriteId">车辆与业务配置重写Id</param>
        /// <response code="200">获取车辆与业务配置重写</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{vehicle_business_mapping_overwrite_id}")]
        [ProducesResponseType(typeof(VehicleBusinessMappingOverwriteDto), 200)]
        public IActionResult Get([FromRoute(Name = "vehicle_business_mapping_overwrite_id")] int vehicleBusinessMappingOverwriteId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingOverwriteService.Get(vehicleBusinessMappingOverwriteId));
        }
        #endregion

        #region 获取车辆与业务配置重写列表
        /// <summary>
        ///  获取车辆与业务配置重写列表
        /// </summary>
        /// <response code="200">获取车辆与业务配置重写列表</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(VehicleBusinessMappingOverwriteDto), 200)]
        public IActionResult Get()
        {
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingOverwriteService.GetList(this.Admin));
        }
        #endregion

        #region 获取车辆与业务配置重写（分页）
        /// <summary>
        ///  获取车辆与业务配置重写（分页）
        /// </summary>
		/// <param name="provinceCode">省份编码</param>
		/// <param name="cityCode">城市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="vehicleTypeId">车型Id</param>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置Id</param>
        /// <param name="enabled">是否启用</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取车辆与业务配置重写（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<VehicleBusinessMappingOverwriteDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "vehcile_type_id")] int? vehicleTypeId,
            [FromQuery(Name = "vehicle_transport_business_config_id")] int? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "sort_name")] string sortName,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "index")] int index = 1,
            [FromQuery(Name = "size")] int size = 10)
        {
            long? agentRecordId = null;
            if (this.Admin.AgentRecord != null) {
                agentRecordId = this.Admin.AgentRecord.AgentRecordId;
            }
            return StatusCode((int)HttpStatusCode.OK, this.vehicleBusinessMappingOverwriteService.Query(agentRecordId, provinceCode, cityCode, countyCode, vehicleTransportBusinessConfigId, vehicleTypeId, enabled, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 启用/禁用车辆与业务配置重写
        /// <summary>
        ///  启用/禁用车辆与业务配置重写
        /// </summary>
        /// <param name="vehicleBusinessMappingOverwriteId">车辆与业务配置重写Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用车辆与业务配置重写成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{vehicle_business_mapping_overwrite_id}/{enabled}")]
        [Log("启用/禁用车辆与业务配置重写")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "vehicle_business_mapping_overwrite_id")] int vehicleBusinessMappingOverwriteId,
            [FromRoute(Name = "enabled")] bool enabled)
        {
            if (enabled)
            {
                this.vehicleBusinessMappingOverwriteService.Enabled(this.Admin, vehicleBusinessMappingOverwriteId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.vehicleBusinessMappingOverwriteService.Disabled(this.Admin, vehicleBusinessMappingOverwriteId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}

